/**
 * 产品树菜单
 * @authors supmain (mtingfeng@gmail.com)
 * @date    2015-01-17 10:46:15
 * @for 产品购买.html
 * @version $1.0$
 */
var consodesk = {
	log: function( msg ){
		if(window && window.console && window.console.log){
			console.log( msg );
		}
	},
	warn: function( msg ){
		if( window && window.console && window.console.warn ){
			console.warn( msg );
		}
	}
};
var BSTYUN = BSTYUN || {};
BSTYUN.zTree = {
	init: function( obj ){
		var that = this;
		try{
			var zNodes = SYSTEM.zNodes;
		}catch(e){
			consodesk.warn("树初始化需要树结构数据!");
			return false;
		};
		if( !$.isArray(zNodes) ){
			consodesk.warn("树结构数据错误!");
			return false;
		};
		var $panel = obj instanceof jQuery ? obj : $( obj );
		var setting = {
				view: {
					showIcon: false,
					showLine: false,
					dblClickExpand: false
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				callback: {
					beforeClick: function( event , treeId , treeNode ){
					},
					onClick: clickTreeNode
				}
			};
		var ztree = $.fn.zTree.init( $panel , setting, zNodes);
		try{
			OpenParentNode( ztree.getNodeByParam("id", treeNodeId , null) , ztree );
		}catch(e){
			if( window.console ){
				console.log("打开子节点出错，请传入正确的节点ID！");
			};
		};
		// 默认打开节点
		function OpenParentNode(node,zTree) {
            var parentNode = node.getParentNode();
            if (parentNode != null) {
                zTree.expandNode(parentNode, true, true, true);
                OpenParentNode(parentNode, zTree);
            };
		};
		// 点击树事件
		function clickTreeNode( event , treeId , treeNode ){
			var zTree = $.fn.zTree.getZTreeObj( $panel.attr("id") );
			// 更新右侧分类详细
			that.updateCommonRightList( treeNode.id ,'');
			if ( treeNode.isParent ) {
				zTree.expandNode(treeNode);
				return false;
			};
			
		};
	},
	updateCommonRightList: function( id ,typeName){
		location.href = "/mall/dhlist/"+id;
	},
	updateCommonRightDetail: function( id ){
		location.href = "/mall/dhdetail/"+id;
	}
};
var updateCommonRightDetail = BSTYUN.zTree.updateCommonRightDetail;
var updateCommonRightList = BSTYUN.zTree.updateCommonRightList;
$(function(){
	BSTYUN.zTree.init( $("#zTreeNavigator") );
});
